package com.rinlink.gateway.jt808;

import io.github.hylexus.jt808.boot.annotation.EnableJt808ServerAutoConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
@EnableJt808ServerAutoConfig
public class Application {

    static Logger logger = LoggerFactory.getLogger(Application.class);
/*

    public static void aliyunKafka() throws InterruptedException {
        System.setProperty("java.security.auth.login.config","C:\\Users\\yhyde\\Documents\\projects\\rinlink-jt808-gateway\\src\\main\\resources\\kafka_client_jaas.conf");


        Map map = new HashMap();

        Executor executor = Executors.newFixedThreadPool(3);
        AtomicInteger count = new AtomicInteger();
        Runnable poll = ()->{
            //      map.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"kafka-0.kafka-headless.default.svc.cluster.local:9092,kafka-1.kafka-headless.default.svc.cluster.local:9092,kafka-2.kafka-headless.default.svc.cluster.local:9092");
            //map.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"101.200.243.11:9093,123.56.148.63:9093,101.200.231.191:9093");
            map.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"101.200.243.11:9093");
            map.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,StringDeserializer.class);
            map.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,StringDeserializer.class);
            map.put(ConsumerConfig.GROUP_ID_CONFIG,"jt808-consumer-t1");
            map.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,"C:\\Users\\yhyde\\Documents\\projects\\rinlink-jt808-gateway\\src\\main\\resources\\kafka.client.truststore.jks");
            //根证书store的密码，保持不变。
            map.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "KafkaOnsClient");
            map.put(SaslConfigs.SASL_MECHANISM, "PLAIN");
            map.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_SSL");
            map.put("ssl.endpoint.identification.algorithm", "");





            KafkaConsumer kafkaConsumer = new KafkaConsumer(map);
            kafkaConsumer.subscribe(Lists.newArrayList("jt808request2"));
            while (true){
                ConsumerRecords records = kafkaConsumer.poll(Duration.ofSeconds(10));
                logger.debug("count: {}",count.addAndGet(records.count()));
            }
        };
        executor.execute(poll);
        executor.execute(poll);
        executor.execute(poll);
        Thread.sleep(Integer.MAX_VALUE);

    }



    public static void kafka2() throws InterruptedException {


        Map map = new HashMap();

        Executor executor = Executors.newFixedThreadPool(3);
        AtomicInteger count = new AtomicInteger();
        Runnable poll = ()->{
            map.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"172.17.1.239:9092,172.17.1.238:9092,172.17.1.237:9092");
            map.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,StringDeserializer.class);
            map.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,StringDeserializer.class);
            map.put(ConsumerConfig.GROUP_ID_CONFIG,"iot-async-dev-data");

            KafkaConsumer kafkaConsumer = new KafkaConsumer(map);
            kafkaConsumer.subscribe(Lists.newArrayList("AliSubscribeMessage_E915s_Order"));
            while (true){
                ConsumerRecords records = kafkaConsumer.poll(Duration.ofSeconds(10));
                logger.debug("count: {}",count.addAndGet(records.count()));
            }
        };
        executor.execute(poll);
        executor.execute(poll);
        executor.execute(poll);
        Thread.sleep(Integer.MAX_VALUE);

    }

    public static void self(){

    }
*/


    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);

    //    kafka2();

    }

}
